broken_wrap = {}
function broken_wrap.setBroken(brokenNode,preAspectType,noEffectCenter, isVerticalMove, isHorizontalMove, strokeSizeR, strokeSizeG, strokeSizeB, autoOri)
    local config = KuruEngine.getInstance():getCameraConfig()

	if( (autoOri == 1) and (config.deviceOrientation == 90 or config.deviceOrientation == 270) ) then
		local tmp = isVerticalMove
		isVerticalMove = isHorizontalMove
		isHorizontalMove = tmp
		print("----ori rev----")
	end
    
	if(isHorizontalMove ~= 0.0) then
		strokeSizeR = strokeSizeR / 720.0
		strokeSizeG = strokeSizeG / 720.0
		strokeSizeB = strokeSizeB / 720.0

	elseif(isVerticalMove ~= 0.0) then
		if(preAspectType == CameraConfigAspectRatio.NINE_TO_SIXTEEN) then
			strokeSizeR = strokeSizeR / 1280.0
			strokeSizeG = strokeSizeG / 1280.0
			strokeSizeB = strokeSizeB / 1280.0
			
		elseif(preAspectType == CameraConfigAspectRatio.THREE_TO_FOUR or preAspectType == CameraConfigAspectRatio.ONE_TO_ONE) then
			strokeSizeR = strokeSizeR / 960.0
			strokeSizeG = strokeSizeG / 960.0
			strokeSizeB = strokeSizeB / 960.0
		end
	else
		strokeSizeR = 0
		strokeSizeG = 0
		strokeSizeB = 0
	end

	brokenNode:getMaterial():getParameter("noEffectCenter"):setFloat(noEffectCenter)
	brokenNode:getMaterial():getParameter("verticalMove"):setFloat(isVerticalMove)
	brokenNode:getMaterial():getParameter("horizontalMove"):setFloat(isHorizontalMove)
	brokenNode:getMaterial():getParameter("strokeSizeR"):setFloat(strokeSizeR)
	brokenNode:getMaterial():getParameter("strokeSizeG"):setFloat(strokeSizeG)
	brokenNode:getMaterial():getParameter("strokeSizeB"):setFloat(strokeSizeB)

end

function broken_wrap.setShake(shakeNode)

	local config = KuruEngine.getInstance():getCameraConfig()

	--const
	local shakeSize = 0.01
	local isPortrait = 1.0

	if(config.deviceOrientation == 90 or config.deviceOrientation == 270) then
		shakeNode:getMaterial():getParameter("isPortrait"):setFloat(0.0)
	else 
		shakeNode:getMaterial():getParameter("isPortrait"):setFloat(1.0)
	end

	math.randomseed(os.time() - os.clock() * 1000)
	local type = math.random(0, 5)

	local bounds = nil
	local yDelta = 0

	if(type == 0 or type == 3) then
		bounds = Vector2.create(0.0, 0.13)

	elseif(type == 1 or type == 4) then
		bounds = Vector2.create(0.13, 0.2)

	elseif(type == 2 or type == 5) then
		bounds = Vector2.create(0.0, 0.2)
		yDelta = 1.0 / 8.0
	end

	if(type >= 3) then
		local tmp = bounds.x
		bounds.x = 1.0 - bounds.y
		bounds.y = 1.0 - tmp
	end	
	
	if(isPortrait == 1.0) then
		bounds.y = bounds.y + yDelta
	end

	shakeNode:getMaterial():getParameter("bounds"):setVector2(bounds)
end



function broken_wrap.setScratch(scene,scratchNode)

	--const--
	local config = KuruEngine.getInstance():getCameraConfig()

	local channelBounds = 0.01
	local channelScale = 3.0
	local rowResolution = 0

	if(config.deviceOrientation == 90 or config. deviceOrientation == 270)  then
		scratchNode:getMaterial():getParameter("isPortrait"):setFloat(0.0)
	else 
		scratchNode:getMaterial():getParameter("isPortrait"):setFloat(1.0)
	end


	math.randomseed(os.time() - os.clock() * 1000)

	local rand1 = math.random(0, 10) / 10.0 

	local scratchBounds1 = Vector3.create(math.max(rand1 - channelBounds, 0.0),
										  math.min(rand1 + channelBounds, 1.0),
										  rand1)								 
	local rand2 = math.random(0, 10) / 10.0 					

	local scratchBounds2 = Vector3.create(math.max(rand2 - channelBounds, 0.0),
										  math.min(rand2 + channelBounds, 1.0),
										  rand2)

	
	if(scratchBounds1.y < scratchBounds2.y) then
		scratchNode:getMaterial():getParameter("bounds1"):setVector3(scratchBounds1)
		scratchNode:getMaterial():getParameter("bounds2"):setVector3(scratchBounds2)
	else 
		scratchNode:getMaterial():getParameter("bounds1"):setVector3(scratchBounds2)
		scratchNode:getMaterial():getParameter("bounds2"):setVector3(scratchBounds1)
	end
	
	--vhsW = 480.0 --> low resolution x

	local config = KuruEngine.getInstance():getCameraConfig()

	curRes = scene:getResolution()
	designResX = 720.0
	designResY = curRes.y * (720.0 / curRes.x)
	texelScaleX = curRes.x / designResX
	texelScaleY = curRes.y / designResY
	
	scratchNode:getMaterial():getParameter("texelWidth"):setFloat(channelScale * texelScaleX / curRes.x)
	scratchNode:getMaterial():getParameter("texelHeight"):setFloat(channelScale * texelScaleY / curRes.y)

end
